home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK2.toast / Development Kits (Disc 2) / ScriptX / Draggable ScriptX Folders / utils / DTK / Examples / Builder / builder.sx next >
Encoding:
Text File  |  1995-12-19  |  4.6 KB  |  140 lines  |  [TEXT/ttxt]

  1. <<<
  2. append theContainerSearchList (parentDir (parentDir theScriptDir))
  3. global dtkLib := open LibraryContainer dir:(parentDir theScriptDir) path:"DTKSaver.sxl"
  4. global ccLib := open LibraryContainer dir:(parentDir theScriptDir) path:"CustClass.sxl"
  5.  
  6. module Builder
  7.     uses ScriptX
  8.     uses DTKSaver
  9.     uses CustomClassesInterface
  10.     exports BuildATitle
  11. end
  12.  
  13. fileIn theScriptDir name:"globals.lib" module:@Builder
  14.  
  15. in module Builder
  16.  
  17. function getClassByName cName ->
  18. (
  19.     chooseOne (allInstances RootClass) (obj name-> return ((obj as String) = name)) cName
  20. )
  21.  
  22. function labelFromFrame theFrame dirInfo->
  23. (
  24.     local lblList := dirInfo[@markers]
  25.     local newName := undefined
  26.     for lblNum := 1 to lblList.size do (
  27.         if lblList[lblNum].start = theFrame do (
  28.             newName := lblList[lblNum].label
  29.             exit
  30.         )
  31.     )
  32.     if newName = undefined do (
  33.         newName := new String
  34.         format newName "Frame_%*" theFrame @unadorned
  35.     )
  36.     return newName
  37. )
  38.  
  39. function BuildATitle director->
  40. (
  41.     format debug "\n***************\n* BuildATitle *\n***************\n" undefined undefined
  42.     local w := new stage boundary:(director[@stageRect]) centered:true
  43.     local cast := director[@cast]
  44.     for frame in director[@score] do (
  45.         local spriteChannels := frame[@spriteChannels]
  46.         local newClass := undefined
  47.         local frameScript := spriteChannels[1][@lingoscript]
  48.         if frameScript <> undefined do (
  49.             local script := frameScript
  50.             local newClassName := findSXKey(script, "Class")
  51.             if newClassName = "Scene" do (
  52.                 print "--------- SCENE -------------" --debug
  53.                 local newScene := new Scene lingo:script boundary:(w.bbox)
  54.                 newScene.fill := new Brush color:(director[@backColor])
  55.                 local sceneName := labelFromFrame(frame[@absoluteFrameNumber], director)
  56.                 newScene.name := sceneName
  57.                 local sceneHelp := getKeyOne director[@castNames] ((sceneName + "help") as string)
  58.                 if sceneHelp = empty then
  59.                     setHelp newScene undefined
  60.                 else
  61.                     setHelp newScene cast[sceneHelp]
  62.                 addScene w newScene sceneName
  63.                 format debug "Name: %*\n" sceneName @unadorned
  64.                 local sndCast
  65.                 for snd in frame[@soundChannels] do (
  66.                     if snd <> 0 do (
  67.                         newScene.sceneAudio := cast[snd]
  68.                         format debug "Sound found for scene %1: %2(%3)\n" #(sceneName,(newScene.sceneAudio as string),snd) #(@unadorned,@unadorned)
  69.                     )
  70.                 )
  71.                 local castIndex
  72.                 local spriteInfo
  73.                 for s := 2 to 24  do (
  74.                     spriteInfo := spriteChannels[s]
  75.                     castIndex := spriteInfo[@castIndex]
  76.                     if castIndex > 0 do (
  77.                         local lingoScript := spriteInfo[@lingoScript]
  78.                         local customClass := findSXKey( lingoScript, "Class")
  79.                         local myCast := cast[castIndex]
  80.                            local newObj
  81.                         if customClass = undefined then (
  82.                         if findSXKey( lingoScript, "Ignore") = undefined then(
  83.                                 if isAKindOf myCast TextPresenter then (
  84.                                     newObj :=  myCast
  85.                                 ) else (
  86.                                     newObj :=  (new TwoDShape boundary:myCast.boundary)
  87.                                 )
  88.                                 newObj.stationary := true
  89.                             ) else(
  90.                                 newObj := undefined
  91.                             )
  92.                         ) else (
  93.                             local custClass := custClassList[customClass as stringConstant]
  94.                             if custClass = empty then (
  95.                                 format debug "-- ** ERROR: custom class not found (%*)\n" customClass @unadorned
  96.                             ) else (
  97.                                 format debug "Instantiating a custom %*...\n" (customClass) @unadorned
  98.                                 newObj := new custClass castNum:castIndex lingo:lingoScript dirInfo:(director) score:(director[@score]) currScene:(newScene)
  99.                             )
  100.                         )
  101.                         if newObj = undefined then (
  102.                             format debug "Element skipped..." undefined undefined
  103.                         ) else (
  104.                             newObj.x := spriteInfo[@x]
  105.                             newObj.y := spriteInfo[@y]
  106.                             local bndry := newObj.boundary
  107.                             if  isAKindOf bndry Bitmap do (
  108.                                 case spriteInfo[@ink] of
  109.                                     @invisible:    bndry.invisibleColor := whiteColor
  110.                                     @matte:    bndry.matteColor := whiteColor
  111.                                 end
  112.                             )
  113.                             if customClass = "Animation" then (
  114.                                 newObj.authorData := w
  115.                                 append newScene.players newObj
  116.                             ) else (
  117.                                 prepend newScene newObj
  118.                             )
  119.                             format debug "Element: %1\tink: %2\n" #((getClassName newObj), spriteInfo[@ink]) #(@unadorned,@unadorned)
  120.                         )
  121.                     )
  122.                 )
  123.             )
  124.         )
  125.     )
  126.     print "--------- END -------------" --debug
  127.     return w
  128. )
  129. in module scratch
  130. (
  131.     local lc := new libraryContainer path:"builder.sxl" dir:(parentdir thescriptdir)
  132.     addUser dtkLib lc
  133.     addUser ccLib lc
  134.     append lc (getModule @builder)
  135.     lc.startupAction := (lc->load lc[1])
  136.     close lc
  137. )
  138. -->>>
  139. quit()
  140.